﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class MucDichSuDungDAL : BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT * from mucdichsudung";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @" DELETE FROM mucdichsudung WHERE ma_md = '{0}' ";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Muc_Dich_Su_Dung)obj;
            string sql = @"INSERT INTO mucdichsudung(ma_md,diengiai,dinhmuc,gia) VALUES('{0}',N'{1}',{2},{3})";
            sql = string.Format(sql,o.ma_md,o.dien_giai,o.dinh_muc,o.gia);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Muc_Dich_Su_Dung)obj;
            string sql = @"UPDATE mucdichsudung SET diengiai=N'{0}',Dinhmuc={1},gia={2} WHERE ma_md='{3}' ";
            sql = string.Format(sql,o.dien_giai,o.dinh_muc,o.gia,o.ma_md);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        

    }
}
